﻿<%@ WebHandler Language="C#" Class="combobox" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using jsm.SqlHelper;
using dbcaac;

public class combobox : IHttpHandler
{
    public void ProcessRequest (HttpContext context) {

        string name = context.Request["name"];
        SqlDataReader reader = null;      
        try
        {
            reader = SqlServerHelper.ExecuteReader(string.Format("SELECT * from [{0}]", name));
        }
        catch
        {
            ExceptionHelper.Throw404Exception(context);
        }
        string json = JsonHelper.GetComboBoxJSON(getIdField(name), getTextField(name), reader);

        context.Response.ContentType = "text/plain";
        context.Response.Write(json);
        context.Response.End(); 
    } 
    
    public bool IsReusable {
        get {
            return false;
        }
    }

    private string getIdField(string comboName)
    {
        string idField = null;
        if ("JCYZY" == comboName.ToUpper())
        {
            idField = "jcyzyId";
        }
        else
        {
            throw new NotImplementedException();
        }
        return idField;
    }
    
    private string getTextField(string comboName)
    {
        string textField = null;
        if ("JCYZY" == comboName.ToUpper())
        {
            textField = "jcyzyName";
        }
        else
        {
            throw new NotImplementedException();
        }
        return textField;
    }
}